<template>
	<view>
		<uni-forms :model="form" style='padding: 20px;'>
			<uni-forms-item required label="描述">
				<uni-easyinput style='width: 260px;' v-model="form.title" type="textarea" placeholder="请输入朋友圈描述内容"></uni-easyinput>
			</uni-forms-item>
			<uni-forms-item label="照片" required>
				<uni-file-picker  @select="select"  limit="3"  :image-styles="imageStyle" v-model="form.jiatu" fileMediatype="image" />
			</uni-forms-item>
			<uni-forms-item>
				<button @click="sendF" style='width: 300px;margin-top: 50px;' type="primary">发送到朋友圈</button>
			</uni-forms-item>
		</uni-forms>
	</view>
</template>

<script>
	import {sendfriend} from '../../service/index.js'
	export default {
		data() {
			return {
				imageStyle:{
					width:'85px',
					height:'85px',
					border:{
						color:'#007aff',
						width:'2px',
						style:'dashed',
						radius:'2px'
					}
				},
				form:{
					title:'',
					contentPic:[],
					jiatu:[]
				}
			}
		},
		methods: {
			select(e){
				//console.log(e)
				uni.uploadFile({
					url:'http://localhost:9000/upload',
					filePath:e.tempFilePaths[0],
					name:'avatar',
					success:(res)=>{
						//console.log(res)
						//console.log(JSON.parse(res.data).filename)
						let a='http://localhost:9000/'+JSON.parse(res.data).filename
						this.form.contentPic.push(a)
						//console.log(this.form.contentPic);
					}
				})
			},
			async sendF(){
				let userName=uni.getStorageSync('userName')
				let title=this.form.title
				let avatar=uni.getStorageSync('avatar')
				let contentPic=this.form.contentPic.join(',')
				//console.log(contentPic);
				let data=await sendfriend(userName,title,avatar,contentPic)
				//console.log(data)
				if(data.code==200){
					uni.switchTab({
						url:'/pages/friend/friend'
					})
					setTimeout(()=>{
						uni.showToast({
							title:'发朋友圈成功',
							icon:'success',
							duration:2000
						})
					},100)
					
				}
			},
		}
	}
</script>

<style lang="scss" scoped>
	.uni-forms-item{
		width: 100%;
	}
</style>
